home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Intuition / boopsi / demoimage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  3.5 KB  |  154 lines

  1. /* demoimage.c -- demonstration of         :ts=8
  2.  * private image class.
  3.  */
  4.  
  5. /*
  6. Copyright (c) 1989, 1990 Commodore-Amiga, Inc.
  7.  
  8. Executables based on this information may be used in software
  9. for Commodore Amiga computers. All other rights reserved.
  10. This information is provided "as is"; no warranties are made.
  11. All use is at your own risk, and no liability or responsibility
  12. is assumed.
  13. */
  14.  
  15. #include "sysall.h"
  16.  
  17. #define D(x)    ;
  18.  
  19. struct  IntuitionBase   *IntuitionBase;
  20. struct  GfxBase         *GfxBase;
  21. struct  Library         *UtilityBase;
  22.  
  23. /* our private class is the "embossed box class"    */
  24.  
  25. /* class pointer is an abstract handle    */
  26. void    *EmbBClass = NULL;
  27. void    *initEmbBClass();
  28.  
  29. /* from varargs.c -- interface to NewObjectA()    */
  30. Object    *NewObject();
  31.  
  32. ULONG    myiflags = CLOSEWINDOW;
  33.  
  34. struct Image    *myimage;
  35.  
  36. main()
  37. {
  38.     struct DrawInfo    *GetScreenDrawInfo();
  39.     struct Window     *OpenWindowTags();    /* in varargs.c for now */
  40.     struct Window    *w;
  41.     struct DrawInfo    *drinfo;
  42.  
  43.     openAll();    /* get libraries open    */
  44.  
  45.     D( printf("about to openwindow\n") );
  46.     w = OpenWindowTags( NULL, 
  47.         WA_Title,    "myimage Test Window",
  48.         WA_SimpleRefresh, TRUE,
  49.         WA_NoCareRefresh, TRUE,
  50.         WA_DepthGadget,    TRUE,
  51.         WA_DragBar,    TRUE,
  52.         WA_Left,    300,
  53.         WA_Top,        50,
  54.         WA_Width,    280,
  55.         WA_Height,    120,
  56.         WA_IDCMP,    myiflags,
  57.         WA_CloseGadget,    TRUE,
  58.             TAG_END );
  59.     D( printf("window at %lx\n ", w ) );
  60.     if ( w == NULL) cleanup( "couldn't open my window.\n");
  61.  
  62.     drinfo = GetScreenDrawInfo( w->WScreen );
  63.  
  64.     /* init my private class    */
  65.     EmbBClass = initEmbBClass();
  66.  
  67.     /* create an image from my private class    */
  68.     myimage =  (struct Image *) NewObject( EmbBClass, NULL,  
  69.             IA_WIDTH, 20,
  70.             IA_HEIGHT, 10,
  71.                 TAG_END );
  72.  
  73. #define XPOS    (40)
  74. #define YPOS    (20)
  75. #define XPOS2    (XPOS + 30)
  76.  
  77.     /* draw the image    */
  78.     DrawImageState( w->RPort, myimage, XPOS, YPOS, IDS_NORMAL, drinfo );
  79.  
  80.     /* draw the image    */
  81.     DrawImageState( w->RPort, myimage, XPOS2, YPOS, IDS_SELECTED, drinfo );
  82.  
  83.     /* go away and be done    */
  84.     goHandleWindow( w );
  85.  
  86.     FreeScreenDrawInfo( w->WScreen, drinfo );
  87.     CloseWindow( w );
  88.  
  89.     DisposeObject( myimage );
  90.     D( printf("have disposed.\n") );
  91.  
  92.     /* get rid of the private class.
  93.      * Don't really exit unless the class can be free'd,
  94.      * since that would mean that somebody might want to use
  95.      * your class's implementation routines after you're gone.
  96.      */
  97.     if ( ! freeEmbBClass( EmbBClass ) )
  98.     {
  99.     cleanup( "PANIC: exiting with class not free'd!\n" );
  100.     }
  101.  
  102.     cleanup( "all done" );
  103. }
  104.  
  105. cleanup( str )
  106. char    *str;
  107. {
  108.     if (str) printf("%s\n", str);
  109.  
  110.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  111.     if (GfxBase) CloseLibrary(GfxBase);
  112.     if (UtilityBase) CloseLibrary(UtilityBase);
  113.  
  114.     exit (0);
  115. }
  116.  
  117. /* exits via cleanup() if failure    */
  118. openAll()
  119. {
  120.     if (!(UtilityBase=(struct Library *)OpenLibrary("utility.library",36L)))
  121.     { cleanup("no V36 utility library\n"); }
  122.  
  123.     if (!(IntuitionBase = 
  124.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  125.     { cleanup("no V36 intuition library\n"); }
  126.  
  127.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36L)))
  128.     { cleanup("no V36 graphics library\n"); }
  129. }
  130.  
  131. goHandleWindow( w )
  132. struct Window    *w;
  133. {
  134.     struct IntuiMessage *imsg;
  135.     for(;;)
  136.     {
  137.     WaitPort( w->UserPort );
  138.     while ( imsg = (struct IntuiMessage *) GetMsg( w->UserPort ) )
  139.     {
  140.         switch ( imsg->Class )
  141.         {
  142.         case CLOSEWINDOW:
  143.             ReplyMsg( (struct Message *) imsg );
  144.         return;
  145.  
  146.         default:
  147.         D( printf("unknown message \n", imsg->Class));
  148.         break;
  149.         }
  150.         ReplyMsg( (struct Message *) imsg );
  151.     }
  152.     }
  153. }
  154.